import { defineStore } from 'pinia'
import $ajax from '@/ajax/admin_ajax.js'
//
const controller = '/role'

const useSysinfoStore = defineStore('sysinfo', {
  state: () => {
    return {
      sysinfos: [],
      sysinfotree: {},
      checkedKeys: [],
      // 控制抽屉的显示与隐藏
      now: new Date().getTime()
    }
  },
  // 定义计算属性
  getters: {
    treeNodes(state) {
      return [state.sysinfotree]
    }
  },
  actions: {
    async loadAuth4Role(roleid) {
      const path = controller + '/q/findall/sysnodeid/byroleid/' + roleid
      const { data: res } = await $ajax.get(path)
      this.checkedKeys = res.result

      this.now = new Date().getTime()
      console.log(this.now)
    },
    async findAllSysnodesTree() {
      const path = controller + '/q/findall/sysnodes/tree'
      const { data: res } = await $ajax.get(path)
      if (res.code === 200) {
        this.sysinfotree = res.result
      }
    },

    async findSysnodesByempno() {
      const empno = 8000
      // sessionllll
      const path = controller + '/q/findall/sysnodes/list/' + empno
      const { data: res } = await $ajax.get(path)
      if (res.code === 200) {
        this.sysinfos = res.result
      }
    }
  }
})

export default useSysinfoStore
